<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class IcRecord extends Model
{
    protected $table = 'ic_record';

    protected $primaryKey = 'system_number';

    protected $keyType = 'string';

    protected $fillable = [
    	'system_number',
    	'system_datetime',
        'order_systemnumber',
    	'computer_name',
    	'ic_print_code',
    	'ic_id',
    	'have_sfz',
    	'sfzinfo_type',
    	'sfz_number',
    	'sfz_photo_path',
    	'sfz_photo_filename',
    	'remarks'
    ];

    protected $appends = [
        'have_sfz_desc',
        'sfzinfo_type_desc' 
    ];

    const HAVE_SFZ_YES = 'Y';

    const HAVE_SFZ_NO = 'N';

    public static $HAVE_SFZ = [
        self::HAVE_SFZ_YES => '是',
        self::HAVE_SFZ_NO => '否'
    ];

    const SFZINFO_TYPE_AUTO = 'AUTO';

    const SFZINFO_TYPE_MANU = 'MANU';

    public static $SFZINFO_TYPE = [
        self::SFZINFO_TYPE_AUTO => '自动读取身份证信息',
        self::SFZINFO_TYPE_MANU => '人工输入身份证信息'
    ];

    public function getHaveSfzDescAttribute(){
        if(array_key_exists('have_sfz', $this->attributes)){
            return $this->attributes['have_sfz_desc'] = self::$HAVE_SFZ[$this->attributes['have_sfz']];
        }
    }

    public function getSfzinfoTypeDescAttribute(){
        if(array_key_exists('sfzinfo_type', $this->attributes)){
            return $this->attributes['sfzinfo_type_desc'] = self::$SFZINFO_TYPE[$this->attributes['sfzinfo_type']];           
        }
    }

    public function weightdata(){
        return $this->hasOne('\App\Models\Weighdata','order_systemnumber','order_systemnumber');
    }

    public function weightAbnormal(){
        return $this->hasOne('\App\Models\WeighAbnormal','order_systemnumber','order_systemnumber');
    }

    public function flowExtemal(){
        return $this->hasOne('\App\Models\FlowExtemal','order_systemnumber','order_systemnumber');
    }
}
